
//引入字体图标
require('../../libs/fonts/iconfont.css')

// 引入当前cless
require('./index.less')

const t=require('../../utlis/toast')

//引入axios
const axios=require('../../utlis/axios')

//引入底部导航
const nav =require('../../utlis/footer-')
nav.showNav('home')

//引入dom.js
const{$,g,ga}=require('../../utlis/dom')


// 引入轮播图
const {Swiper,Autoplay,Navigation, Pagination} = require('swiper');    
require('swiper/css')
require('swiper/css/pagination')

$(function(){

    // 配置轮播图
    const swiper = new Swiper('.swiper', {

        modules: [Autoplay,Navigation, Pagination],
        loop: true, // 循环模式选项
    
        // 如果需要分页器
        pagination: { //分页器
            el: ".swiper-pagination",
            clickable: true,
        },
        
        autoplay: { //自动播放
            delay: 2000,
            disableOnInteraction: false,
        },
    }); 

    /**
     * 获取元素
     */
     const rbox = g('.rbox')
     const clockday = g('.clockday')
     const clockBtn = g('.clockBtn')
     const badgenum = g('.badgenum')


    /**
     * 获取用户信息
     */
    axios.get('/api/user/info').then(function(res){
        if(res.data.errno === 0){
            rbox.textContent=res.data.data.ranking
            clockday.textContent=res.data.data.clockCount
            badgenum.textContent=res.data.data.badges
        };
    })

    /**
     * 今日打卡
     */
     clockBtn.addEventListener('click',function(){
        // console.log(1);
        axios.post('/api/user/clockIn').then(function(res){
            // console.log(res);
            if(res.data.errno === 0){
                clockday.textContent= +clockday.textContent + 1
                clockBtn.textContent='今日已打卡' ;
                t.toast('打卡成功')
            }else{
                t.toast('打卡失败,已打卡')
            };
        })
     })

    /**
     * 获取用户打卡信息
     */
    axios.get('/api/user/clockInInfo').then(function(res){
        if(res.data.errno===0){
            clockBtn.textContent=res.data.data.isClockIn ? '今日已打卡' :'今日打卡'
        }
    })






})